const app = getApp();
const common = require('../../../utils/common.js');
const api = require('../../../config/api.js');

Page({
  data: {
    imgUrl: app.globalData.imgurl,
    orderId: 0,
    orderInfo: {},
    orderGoods: [],
    order_status_text: '',
    boxShow:false ,
    reason: '',
    tihuo_show: false,
		type: ''
  },
	onLoad: function (options) {
		this.setData({
			orderId: options.orderId,
			type: options.type
		});
	},
	onShow: function () {
		this.getOrderDetail();
	},
  openTihuo: function () {
    this.setData({
      tihuo_show: true
    });
  },
  closeTihuo: function () {
    this.setData({
      tihuo_show: false
    });
  },
  getOrderDetail: function () {
    let that = this;
    var data = {
      orderId: that.data.orderId
    }
		common.request(api.OrderDetail, data, 'POST').then(function (data) {
      if (data.type == 'success') {
        that.setData({
          orderInfo: data.data.orderInfo,
          orderGoods: data.data.orderGoods,
          order_status_text: data.data.order_status_text,
          order_create_time: data.data.order_create_time
        });
      } else {
        console.log(data.content);
      }
    });
  },
  productDetail: function (e) {
    var productStockId = e.currentTarget.dataset.productStockId;
    wx.navigateTo({
      url: '/pages/goods/goods?productSkuId=' + productStockId
    })
  },
	//核销订单
	staffTihuo: function () {
		var that = this;
		wx.showModal({
			title: '提示',
			content: '确认核销订单吗',
			success: function (res) {
				var data = {
					orderId: that.data.orderId
				}
				if (res.confirm) {
					common.request(api.OrderStaffTiHuo, data, 'POST').then(function (data) {
						if (data.type == 'success') {
							common.showSuccessToast(data.content);
							setTimeout(function () {
								wx.navigateBack({ changed: true });
							}, 1500)
						} else {
							common.showErrorToast(data.content);
						}
					});
				} else if (res.cancel) {

				}
			}
		})
	}
})